package com.mingqijia.gassafety.webserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mingqijia.gassafety.db.entity.ServiceComboDetail;
import com.mingqijia.gassafety.db.entity.vo.UserServiceComboVO;
import com.mingqijia.gassafety.db.mapper.ServiceComboDetailMapper;
import com.mingqijia.gassafety.webserver.request.inner.ServiceComboRecordRequest;
import com.mingqijia.gassafety.webserver.service.ServiceComboDetailService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class ServiceComboDetailServiceImpl extends ServiceImpl<ServiceComboDetailMapper, ServiceComboDetail> implements ServiceComboDetailService {

    @Override
    public Boolean addComboDetail(List<ServiceComboDetail> comboDetailList) {
        return this.saveBatch(comboDetailList);
    }

    @Override
    public List<ServiceComboDetail> queryByOrderCode(List<String> orderCodes) {
        QueryWrapper<ServiceComboDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().in(ServiceComboDetail::getOrderCode, orderCodes)
                .eq(ServiceComboDetail::getIsDeleted, 0);
        List<ServiceComboDetail> serviceCombos = this.list(queryWrapper);
        return serviceCombos;
    }

    @Override
    public List<ServiceComboDetail> queryByRecord(ServiceComboRecordRequest request) {
        QueryWrapper<ServiceComboDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(StringUtils.isNotEmpty(request.getOrderCode()), ServiceComboDetail::getOrderCode, request.getOrderCode())
                .eq(StringUtils.isNotEmpty(request.getCode()), ServiceComboDetail::getCode, request.getCode())
                .eq(request.getPkgId() != null && request.getPkgId() > 0, ServiceComboDetail::getPkgId, request.getPkgId())
                .eq(ServiceComboDetail::getIsDeleted, 0);
        List<ServiceComboDetail> serviceCombos = this.list(queryWrapper);
        return serviceCombos;
    }


    @Override
    public UserServiceComboVO getUserServiceCombo(String code, Integer userId, String spId) {
        //code 服务项编码 1-sos报警器 2-漏水报警 3-烟雾报警 4-门锁报警
        List<UserServiceComboVO> userServiceComboVOList = this.baseMapper.getUserServiceCombo(code, userId);
        if (null == userServiceComboVOList || userServiceComboVOList.isEmpty()) {
            return null;
        }
        return userServiceComboVOList.get(0);
    }
}
